/* read the id string */
gbfread(&string_size, 1, 1, tpo_file_in);
- char* string_buffer = (char*) xmalloc(string_size+1);
- gbfread(string_buffer, 1, string_size, tpo_file_in);
-
- /* terminate the string */
- string_buffer[string_size] = 0;
+ QByteArray string_buffer = gbfgetnativecstr(tpo_file_in);
/* check for the presence of a 3.0-style id string */
/* Note this check also finds version 4 id strings, e.g. "TOPO! Ver. 4.5.0" */
//fprintf(stderr,"gpsbabel can only read TPO version 2.7.7 or below; this file is %s\n", string_buffer);
gbfseek(tpo_file_in, -(string_size+1), SEEK_CUR);
- xfree(string_buffer);
tpo_version = 3.0; /* Really any 3.x version */
return;
/* We found a version 1.x or 2.x file */
/* seek back to the beginning of the file */
gbfseek(tpo_file_in, -(string_size+1), SEEK_CUR);
- xfree(string_buffer);
tpo_version = 2.0; /* Really any 1.x or 2.x version */
return;
}
as a C array definition. */
tpo_dump_header_bytes(int header_size)
{
- unsigned char* buffer = (unsigned char*) xmalloc(header_size);
-
- gbfread(buffer, 1, header_size, tpo_file_in);
+ QByteArray buffer = gbfreadbuf(header_size, tpo_file_in);
printf("unsigned char header_bytes[] = {\n");
if (i%8 == 0) {
printf(" ");
}
- printf("0x%02X", buffer[i]);
+ printf("0x%02X", buffer.at(i));
if (i != header_size-1) {
printf(", ");
}
}
printf("};\n");
-
- xfree(buffer);
}
/* tpo_read_until_section()
// clumsy way to skip two undefined bytes (compiler should unwind this)
for (unsigned xx = 0; xx < 2; xx++) {
unsigned int skipped = (unsigned char) gbfgetc(tpo_file_in);
- Q_UNUSED(skipped);
+ Q_UNUSED(skipped)
// printf("Skipping unknown (visibility?) byte 0x%x\n", skipped);
}
}
unsigned char tmp = gbfgetc(tpo_file_in);
- Q_UNUSED(tmp);
+ Q_UNUSED(tmp)
// printf("Skipping unknown byte 0x%x after color\n",tmp);
// byte for name length, then name
return;
}
if (tmp) {
- styles[ii].name[0] = '\0';
- gbfread(styles[ii].name, 1, tmp, tpo_file_in);
- styles[ii].name[tmp] = '\0'; // Terminator
+ styles[ii].name = gbfreadbuf(tmp, tpo_file_in);
} else { // Assign a generic style name
styles[ii].name = QString("STYLE %1").arg(ii);
}
// Process the delta
else {
- int scarray[] = {0,1,2,3,4,5,6,7,-8,-7,-6,-5,-4,-3,-2,-1};
+ static const int scarray[] = {0,1,2,3,4,5,6,7,-8,-7,-6,-5,-4,-3,-2,-1};
if (buf[jj] == 0) {
fatal(MYNAME ": Found bad scales lonscale=0x%x latscale=0x%x\n", lonscale, latscale);
}
- lon+=lonscale*scarray[buf[jj]>>4];
- lat+=latscale*scarray[(buf[jj]&0xf)];
+ lon += lonscale * scarray[buf[jj] >> 4];
+ lat += latscale * scarray[(buf[jj] & 0xf)];
//printf(".");
jj++;
name_length = tpo_read_int();
//printf("\tComment length: %d\n", name_length);
if (name_length) {
- QString comment;
- gbfread(comment, 1, name_length, tpo_file_in);
- waypoint_temp->description = comment;
+ waypoint_temp->description = gbfreadbuf(name_length, tpo_file_in);
}
// For routes (later), we need a duplicate of each waypoint
// Fetch comment length
unsigned int name_length = tpo_read_int();
if (name_length) {
- QString comment;
-
- gbfread(comment, 1, name_length, tpo_file_in);
- waypoint_temp->description = comment;
+ waypoint_temp->description = gbfreadbuf(name_length, tpo_file_in);
}
// Length of text for external path. If non-zero, skip past
name_length = tpo_read_int();
//printf("name_length: %x\n", name_length);
if (name_length) {
- QString notes;
-
- gbfread(notes, 1, name_length, tpo_file_in);
+ QString notes = gbfreadbuf(name_length, tpo_file_in);
waypoint_temp->AddUrlLink(notes);
}
//UNKNOWN DATA LENGTH
name_length = tpo_read_int();
if (name_length) {
- QString notes;
-
- gbfread(notes, 1, name_length, tpo_file_in);
+ QString notes = gbfreadbuf(name_length, tpo_file_in);
waypoint_temp->AddUrlLink(notes);
}
}
-
-
-
// Text Labels decoder for version 3.x files.
//
static void tpo_process_text_labels()